﻿namespace NEvoWeb.Modules.NB_Store
{
    using DotNetNuke.Entities.Portals;
    using Microsoft.VisualBasic;
    using System;
    using System.Collections;
    using System.Web;

    public abstract class GatewayInterface
    {
        private static Hashtable objArray = new Hashtable();
        private static GatewayInterface objProvider = null;

        protected GatewayInterface()
        {
        }

        public abstract void AutoResponse(int PortalID, HttpRequest Request);
        private static void CreateProvider(int PortalID, string ProviderAssembly, string ProviderClass)
        {
            if (ProviderAssembly == "")
            {
                string[] strArray = Strings.Split(SharedFunctions.GetStoreSetting(PortalID, "gateway.provider", "XX"), ",", -1, CompareMethod.Binary);
                ProviderAssembly = strArray[0];
                ProviderClass = strArray[1];
            }
            objProvider = (GatewayInterface) Activator.CreateInstance(ProviderAssembly, ProviderClass).Unwrap();
            objArray.Add(PortalID.ToString() + ProviderAssembly, objProvider);
        }

        public abstract bool GetBankClick(int PortalID, HttpRequest Request);
        public abstract string GetButtonHtml(int PortalID, int OrderID, string Lang);
        public abstract string GetCompletedHtml(int PortalID, int UserID, HttpRequest Request);
        public static GatewayInterface Instance()
        {
            return Instance("", "");
        }

        public static GatewayInterface Instance(string ProviderAssembly, string ProviderClass)
        {
            int portalId = ((PortalSettings) HttpContext.Current.Items["PortalSettings"]).PortalId;
            if (!objArray.ContainsKey(portalId.ToString() + ProviderAssembly))
            {
                CreateProvider(portalId, ProviderAssembly, ProviderClass);
            }
            return (GatewayInterface) objArray[portalId.ToString() + ProviderAssembly];
        }

        public abstract void SetBankRemotePost(int PortalID, int OrderID, string Lang, HttpRequest Request);
    }
}

